package cn.yd.rb.webconfig;

import cn.yd.rb.interceptor.LoginInterceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
//2、创建一个Java类继承WebMvcConfigurerAdapter，并重写 addInterceptors 方法。
public class LoginInterceptorConfiguration implements WebMvcConfigurer {

    //3、实例化自定义的拦截器
    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //如果interceptor中不注入redis或其他项目可以直接new
        //4、将拦截器对像手动添加到拦截器链中（在addInterceptors方法中添加）
        /*String[] excludes= new String[]{"/","/user/toLogin","/user/login","/loginAndRegist.jsp","/admin/login","/admin/login.jsp","/admin/css/**", "/static/**"};
       */
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/admin/index")
                .excludePathPatterns("/admin/login", "/admin/logout");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //对静态资源的放行
    /* registry.addResourceHandler( "/static/**" ).
                addResourceLocations( "classpath:/static/" );*/
//       registry.addResourceHandler( "/admin/js/**" ).
//                addResourceLocations( "classpath:/admin/js/" );

    }


}